import 'package:record/record.dart';
import 'dart:async';

import 'package:web_socket_client/web_socket_client.dart' as ws;

import '../../../utils/tips.dart';


final record = AudioRecorder();

class recordUtil {
  Timer? _timer;
  ws.WebSocket? audioTranlateSocket;
  bool wsServerHaveReady = false;
  bool hasInitRecord = false;

  String srcLang = '';
  String tgtLang = '';


  static initRecorder() async {
    print('initrecord');
    if (await record.hasPermission()) {
      print('checkhere');
      // Start recording to file
      // ... or to stream
      final stream = await record.startStream(
        const RecordConfig(encoder: AudioEncoder.pcm16bits),
      );
      print('checkstream ${stream}');
      return stream;
    }
  }

void connectSocket(String url,String src,String tgt) async{
  Tips.showLoading();
  if(audioTranlateSocket == null){
    audioTranlateSocket =  ws.WebSocket (Uri.parse(url+'&from=${src}&to=${tgt}'),
        headers: {
          'x-api-key': '264e03da4958e5ea405dd8f63b87da898757b821',
        },
        timeout: Duration(seconds: 20));
  }

}

}
